import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import oracle.jdbc.driver.*;


public class Connect {
	Connection cn;
	private Statement st;
	private static Connect instance;

	public static synchronized Connect getInstance() throws Exception {
		if (instance == null) {
			instance = new Connect();
		}
		return instance;
	}

	private Connect() {
		//String url = "jdbc:oracle:thin:@MOSERV:1521:AISGZ";
		String url = "jdbc:oracle:thin:@sakhserv:1521:AISGZ";

		try {
			DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
		} catch (Exception e) {
			e.printStackTrace();
			return;
		}

		try {
			cn = DriverManager.getConnection(url, "aisgz", "aisgz");
			st = cn.createStatement();
		} catch (Exception e) {
			System.out.println(e);
			return;
		} finally {
			System.out.println("All that happened");
		}
	}

	
	public void insert(int j,String table,String field, String name , String edit,String vis) throws SQLException {
	 
		st.executeUpdate("INSERTT INTO AAA_1 VALUES ('" + table + "','"+ field+"','"+name+"','" +edit+"',"+j+",'"+vis+"')" );
		 System.out.println("inserted");
	}

	public List getData(String table, String column) throws SQLException {
		List data = new ArrayList();
		ResultSet rs = st.executeQuery("SELECT " + column + " FROM " + table
				+ " ");
		while (rs.next()) {
			data.add(rs.getString(1));
			// System.out.println("q "+rs.getString(1));
		}
		rs.close();

		return data;
	}

	public void close() throws SQLException {
		st.close();
		cn.close();
	}

	public static void main(String[] args) throws Exception {
		Connect ora = Connect.getInstance();// .insert("sim");
		//ora.getData("a_reg_from_oos", "OOS807");
		// st.executeQuery("SELECT * FROM  ");
		// rs.close();
	}
}
